<template>
  <div class="PersonalCenter">
    <!-- 引入导航栏 -->
    <byd-header />
    <div class="container">
      <!-- 侧边栏 -->
      <el-container>
        <el-aside width="250">
          <div class="sans">
            <h2 style="text-align: left">个人中心</h2>
            <!-- 个人中心 -->
            <img
              v-if="pic"
              :src="require(`../assets/header_pic/header${pic}.jpg`)"
              alt=""
              @click="dialogTableVisible = true"
            />
            <!-- 弹框换头像 -->
            <el-dialog
              title="点击选择头像"
              :visible.sync="dialogTableVisible"
              width="40%"
            >
              <div class="imgs">
                <div
                  v-for="i in 12"
                  :key="i"
                  style="display: inline-block; margin: 10px"
                >
                  <img
                    :src="require(`../assets/header_pic/header${i}.jpg`)"
                    alt=""
                    @click="
                      photo(i);
                      dialogTableVisible = false;
                    "
                  />
                </div>
              </div>
            </el-dialog>

            <p v-if="phone">{{ phone.replace(/(\d{3})(\d{4})(\d{4})/, "$1****$3") }}</p>
          </div>
          <el-menu
            :default-active="this.$route.path"
            class="el-menu-vertical-demo"
            background-color="white"
            text-color="black"
            active-text-color="#00b1a9"
            router
          >
            <!-- 我的收藏 -->
            <el-menu-item index="/centre/collet">
              <i class="el-icon-star-off"></i>
              <span style="font-size: 16px">我的收藏</span>
            </el-menu-item>
            <!-- 我的预约 -->
            <el-menu-item index="/centre/order">
              <i class="el-icon-phone-outline"></i>
              <span style="font-size: 16px">我的预约</span>
            </el-menu-item>
            <!-- 车友圈 -->
            <el-submenu index="3">
              <template slot="title">
                <i class="el-icon-stopwatch"></i>
                <span style="font-size: 16px">车友圈</span>
              </template>
              <el-menu-item-group>
                <template slot="title"></template>
                <!-- 车友圈发帖 -->
                <el-menu-item index="/centre/announce" style="font-size: 16px">
                  <i class="el-icon-notebook-1"></i>我的帖子
                </el-menu-item>
                <!-- 车友圈评论过 -->
                <el-menu-item index="/centre/reply" style="font-size: 16px">
                  <i class="el-icon-notebook-2"></i>我的足迹
                </el-menu-item>
              </el-menu-item-group>
            </el-submenu>
          </el-menu>
        </el-aside>
        <!-- 主体内容 -->
        <el-main>
          <router-view />
        </el-main>
      </el-container>
    </div>
    <byd-footer />
  </div>
</template>

<script>
import { mapMutations } from "vuex";
import BydFooter from "../components/BydFooter.vue";
import BydHeader from "../components/BydHeader.vue";

export default {
  components: { BydHeader, BydFooter },

  created() {
    this.save();
    if (!sessionStorage.getItem("phone")) {
      this.$router.push("/login");
    }
  },
  inject: ["reload"],
  methods: {
    ...mapMutations(["getPic"]),
    photo(i) {
      this.pic = i;
      this.$store.commit("getPic", this.pic);
      this.reload();
    },
    save() {
      this.phone = sessionStorage.getItem("phone");
      this.pic = sessionStorage.getItem("pic");
    },
  },
  data() {
    return {
      pic: "",
      phone: "",
      dialogTableVisible: false,
    };
  },
};
</script>

<style lang="scss" scoped>
// 版心
.container {
  width: 1400px;
  margin: 0 auto;
}
@media (max-width: 1400px) {
  .container {
    width: 1200px;
    margin: 0 auto;
  }
}
@media (max-width: 1200px) {
  .container {
    width: 1024px;
    margin: 0 auto;
  }
}
.PersonalCenter {
  background-color: #ebe7e7;
}
//个人中心
.sans {
  background-color: white;
  .imgs {
    text-align: center;
  }

  h2 {
    padding: 50px 20px 30px;
  }
  img {
    width: 100px;
    border-radius: 50%;
    display: block;
    margin: 10px auto;
  }
  p {
    text-align: center;
    padding-bottom: 20px;
    font-weight: 900;
    font-size: 18px;
  }
}

// 侧边导航栏
.el-menu-vertical-demo:not(.el-menu--collapse) {
  width: 250px;
  // height: calc(100vh - 646px);
  height: 60vh;
}
</style>
